import vue from "@vitejs/plugin-vue";

import createAutoImport from "./auto-import";
import createSvgIcon from "./svg-icon";
import createCompression from "./compression";
import createSetupExtend from "./setup-extend";
import { createHtmlPlugin } from "vite-plugin-html";

export default function createVitePlugins(
  viteEnv,
  isBuild = false,
  version = "1.0.0"
) {
  const { VITE_APP_TITLE } = viteEnv;
  const vitePlugins = [vue()];
  vitePlugins.push(createAutoImport());
  vitePlugins.push(createSetupExtend());
  vitePlugins.push(createSvgIcon(isBuild));
  isBuild && vitePlugins.push(...createCompression(viteEnv));

  // index.html title设置
  vitePlugins.push(
    createHtmlPlugin({
      inject: {
        data: {
          title: VITE_APP_TITLE,
          version,
        },
      },
    })
  );

  return vitePlugins;
}
